//
//  HELBaseViewVC.m
//  HandheldELearn
//
//  Created by wsj2015 on 16/7/11.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELBaseViewVC.h"

#import "YSYRefreshKit.h"
#import <masonry.h>
@interface HELBaseViewVC ()


@property (nonatomic,  strong) YSYRefreshKit *refreshView;
@property(nonatomic, strong)UILabel *noConnectionLabel;
@property(nonatomic, strong)UIView *bannerView;
@end

@implementation HELBaseViewVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
//    self.navigationController.navigationBar.backItem.hidesBackButton = NO;

    [self configUI];
//    self.mode = MMReachabilityModeResize;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //self.noNeedChangeNavbar = NO;
    [self setNavToBlue];
    //self.bannerView.backgroundColor = [UIColor redColor];
    //[self cwq_MonitorNetStatus];
   
}
 -(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //self.noNeedChangeNavbar = YES;
}
-(YSYRefreshKit *)refreshViewWithScrollView:(UIScrollView *)scroll refreshBlock:(void (^)())refreshBlock
{
    if (!_refreshView) {
        // refresh head
        _refreshView = [[YSYRefreshKit alloc] initWithSuperView:self.view withScrollView:scroll];
        _refreshView.mShowView.backgroundColor = kAppBg;
//        _refreshView.mStatusHeight = 64;
        _refreshView.mStatusHeight = -20;
        //    self..mShowView.backgroundColor =
        __weak __typeof(self)weakSelf = self;
        _refreshView.startBlock = ^() {
            if (refreshBlock) {
                refreshBlock();
            }
//            __strong __typeof(weakSelf)strongSelf = weakSelf;
//            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//                [_refreshView endRefresh];
//            });
        };

    }
    return _refreshView;

}
- (void )configUI{

}


- (void)wsj_stopRefresh{
    [self.refreshView endRefresh];
}


- (WLReloadPromptView *)noNetView{
    
    
    //    @property (strong, nonatomic) IBInspectable UIColor *ringColor;         /*< 圆圈的颜色 */
    //    @property (strong, nonatomic) IBInspectable UIColor *WIFIColor;         /*< WIFI Logo 的颜色 */
    //    @property (strong, nonatomic) IBInspectable UIColor *promptTextColor;   /*< 提示文字的颜色 */
    //    @property (strong, nonatomic) IBInspectable UIColor *reloadTitleColor;  /*< 按钮标题的颜色 */
    //    @property (strong, nonatomic) IBInspectable UIColor *borderColor;       /*< 按钮边框的颜色 */
    //    @property (strong, nonatomic) IBInspectable UIColor *borderFillColor;   /*< 按钮背景色 */
    //    @property (copy, nonatomic) IBInspectable NSString *promptText;         /*< 提示文字 */
    //    @property (copy, nonatomic) IBInspectable NSString *reloadTitle;        /*< 按钮标题 */
    //    @property (assign, nonatomic) IBInspectable CGFloat borderRadius;       /*< 按钮边框圆角 */
    //
    //    @property (nullable, copy, nonatomic) void (^reloadActions)(void);      /*< 按钮点击的闭包 */
    if (!_noNetView) {
        _noNetView  =[[WLReloadPromptView alloc] initWithCoveredView:self.view];
        _noNetView.ringColor =kMainColor;
        _noNetView.reloadTitleColor =[UIColor whiteColor];
        _noNetView.borderColor =[UIColor clearColor];
        _noNetView.borderFillColor =[UIColor orangeColor];
        _noNetView.borderRadius = 10;
        [self.view addSubview:_noNetView];
    }
    return _noNetView;
    
}
//标题
- (void)titleView:(NSString *)title {
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    titleLabel.center = CGPointMake(self.view.center.x, 42);
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = title;
    [self.navigationItem setTitleView:titleLabel];
    
}

- (void)setNavToBlue{

//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"wsj_2012"] forBarMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
//    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
////    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
////    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
//    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [[HELAppManager sharedAppManger].appNav resetNav];
}

- (void)isShowBackBtn:(BOOL)isShow{
    
    UIBarButtonItem *item =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(backAction:)];
    if (isShow) {
        self.navigationItem.leftBarButtonItem =item;

    }
    
}

- (void)backAction:(UIButton *)sender{
    if (self.presentingViewController) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}


- (UIView*)bannerView {
    
    if (!_bannerView) {
        
        UIView *bannerView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, 0.0, self.view.frame.size.width, 38.0)];
        [bannerView setBackgroundColor:[UIColor redColor]];
        
        UILabel *noConnectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, 0.0, bannerView.frame.size.width, bannerView.frame.size.height)];
        [noConnectionLabel setFont:[UIFont boldSystemFontOfSize:16]];
        [noConnectionLabel setTextColor:[UIColor whiteColor]];
        [noConnectionLabel setShadowColor:[UIColor blackColor]];
        [noConnectionLabel setText:@"无法连接网络!"];
        [noConnectionLabel setTextAlignment:NSTextAlignmentCenter];
        [noConnectionLabel setBaselineAdjustment:UIBaselineAdjustmentAlignCenters];
        [noConnectionLabel setBackgroundColor:[UIColor clearColor]];
        [noConnectionLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
        
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.frame = noConnectionLabel.bounds;
        gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.8 green:0 blue:0 alpha:0.8] CGColor],
                           (id)[[UIColor colorWithRed:0.4 green:0 blue:0 alpha:0.8] CGColor],
                           nil];
        [bannerView.layer insertSublayer:gradient atIndex:0];
        [bannerView addSubview:noConnectionLabel];
        [self.view.superview addSubview:bannerView];
        [self.view.superview sendSubviewToBack:bannerView];
        _bannerView = bannerView;
       
    }
    
    return _bannerView;
}











@end
